package com.situ.mymall.config;



import com.situ.mymall.converter.String2DateConverter;
import com.situ.mymall.interceptor.LoginInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.format.FormatterRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebConfig implements WebMvcConfigurer {


    //配置Converter,前后台日期的转换
    @Override
    public void addFormatters(FormatterRegistry registry) {
        registry.addConverter(new String2DateConverter());
    }

    //配置虚拟路径
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/pic/**")
                .addResourceLocations("file:/E:/situ/1Project/image/");
        WebMvcConfigurer.super.addResourceHandlers(registry);
    }



    //这个方法用来配置拦截器，我们写的拦截器只有配置了才起作用
    //相当于白名单，有这些才拦截，没有不拦截
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //链式编程
        //把登录的拦截器配置上才能起作用
        // addPathPatterns("/**") 拦截器拦截所有的请求
        // excludePathPatterns 代表哪些请求不需要拦截
        registry.addInterceptor(new LoginInterceptor())
                .addPathPatterns("/page/cart/**","/cart/**","/page/order/**","/order/**");
    }
}
